# -*- coding: utf-8 -*-

import glob
import string
import re
import d15n_routines as r
from salt_file import salt

n = '\x0D\x0A'

if 1: # calculate sha256 digests

    for f in glob.glob('_cleanup_POC_ID_hb2.csv'):

        i = open(f, 'r')
        o = open('_d15n_final' + f, 'wb')
        o.write('Filename\tID\tPerson_NS_d15n' + n)

        for l in i.readlines():

            l = r.remove_eol(l)

            f, id, person_ns = string.split(l, '\t')

            person_ns_d15n = r.sha256(person_ns + salt)

            #test run
            #final run ... original line (l) and bn ommited
            res = "%s\t%s\t%s" % (f, id, person_ns_d15n) + n

            o.write(res)
        o.close()
